<%@ page language="java" import="java.util.*,com.ruohi.util.common.*,com.ruohi.gift.order.OrderStatus" pageEncoding="UTF-8"%><%
	String tableName = "view_gift_order_payoff";
	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	String fileds = "id,uuid,add_date,order_num,order_type,mem_no,receive_name,product_total_price,ship_total_price,order_status,sms_alert_send,offline_pay_remark,ship_remark,pay_gateway_no,(select back_enable_operate from gift_order_status_operate where order_status=view_gift_order_payoff.order_status) as statusoperate,total_crown_partner_payment,total_diamond_partner_payment,total_gold_partner_payment,total_junior_member_payment,payoff_type,p_flag";
	String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
	String mem_no = CommonString.getFormatPara(request.getParameter("mem_no"));
	String whereStr = " and parent_memNo='"+mem_no+"' ";
	String orderByStr = " add_date desc ";

	Map orderStatusMap=new TreeMap();
	orderStatusMap.put("","-请选择-");
	orderStatusMap.put(CommonString.getFormatPara(OrderStatus.CANCELED),OrderStatus.showStatus(OrderStatus.CANCELED));
	orderStatusMap.put(CommonString.getFormatPara(OrderStatus.WAIT_PAY),OrderStatus.showStatus(OrderStatus.WAIT_PAY));
	orderStatusMap.put(CommonString.getFormatPara(OrderStatus.PAYED),OrderStatus.showStatus(OrderStatus.PAYED));
	orderStatusMap.put(CommonString.getFormatPara(OrderStatus.ASSORTING),OrderStatus.showStatus(OrderStatus.ASSORTING));
	orderStatusMap.put(CommonString.getFormatPara(OrderStatus.SHIPPED),OrderStatus.showStatus(OrderStatus.SHIPPED));
	orderStatusMap.put(CommonString.getFormatPara(OrderStatus.FINISHED),OrderStatus.showStatus(OrderStatus.FINISHED));
	orderStatusMap.put(CommonString.getFormatPara(OrderStatus.REFUND),OrderStatus.showStatus(OrderStatus.REFUND));
	
	Map orderTypeMap = new TreeMap();
	orderTypeMap.put("", "-请选择-");
	orderTypeMap.put("0", "普通订单");
	orderTypeMap.put("1", "拍卖订单");
	orderTypeMap.put("2", "团购订单");
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  <body>
  	<div class="searchForm">
  		<div class="searchCondition">
  			<div class="searchList">
		  		<div class="searchLeft">订单号</div>
		  		<div class="searchRight">
		  			<input type="text" class="jr_text" name="order_num" id="order_num" />
		  		</div>
		  	</div>
  			<div class="searchList">
		  		<div class="searchLeft">收货人</div>
		  		<div class="searchRight">
		  			<input type="text" class="jr_text" name="receive_name" id="receive_name" />
		  		</div>
		  	</div>
		  	<div class="searchList" style="width:440px;">
		  		<div class="searchLeft">下单时间</div>
		  		<div class="searchRight" style="width:320px;">
		  			<input type="text" class="Wdate jr_text" style="width:120px;" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});" name="add_date_start" id="add_date_start" />
		  			-
		  			<input type="text" class="Wdate jr_text" style="width:120px;" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});" name="add_date_end" id="add_date_end" />
		  		</div>
		  	</div>
		  	<div class="searchList">
		  		<div class="searchLeft">订单状态</div>
		  		<div class="searchRight">
		  			<select name="order_status" id="order_status" class="jr_select">
		  				<%=CommonForm.createSelect(orderStatusMap,"") %>
		  			</select>
		  		</div>
		  	</div>
		  	<div class="searchList">
		  		<div class="searchLeft">订单类型</div>
		  		<div class="searchRight">
		  			<select name="order_type" id="order_type" class="jr_select">
		  				<%=CommonForm.createSelect(orderTypeMap, "") %>
		  			</select>
		  		</div>
		  	</div>
  		</div>
  		<div class="searchBtn">
  			<input type="button" class="btn" onclick="doSearch();" value="查询" />
  			<input type="button" style="margin-left: 5px;" class="btn" onclick="doClearForm();" value="重置" />
  			<div style="clear:both;"></div>
  			<a href="javascript://void(0);" onclick="exportExcel();">按指定条件导出订单</a>
  		</div>
  	</div>
  	<div style="clear: left;"></div>
  	
	<div class="l-loading" style="display: block" id="pageloading"></div> 
	<div id="maingrid" style="margin: 0; padding: 0"></div>
	<div style="display: none;"></div>
  </body>
</html>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/plugin/date/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script type="text/javascript" src="/backend/scripts/gift_order_operate.js"></script>
<script type="text/javascript">
	var grid;
	var windowWidth = 800;
	var windowHeight = 420;
	var channelUUID = '<%=channelUUID %>';
	var tableName = "<%=tableName %>";
	var fields = "<%=fileds %>";
	var whereStr = "<%=whereStr %>";
	var orderBy = "<%=orderByStr %>";
	var columnsArr = [];
	var url = "";
	var conditionStr = "";
	var params = [];
	jQuery(function() {
		params.push({'name':'enumNo','value':'106013'});
		grid = new Dev21sunGrid({
			toolbar : {
						items : [{
									text : '打开查询',
									click : function() {
										closeAndOpen();
									},
									icon:'right'
								}]
					}
		});
		jQuery("#pageloading").hide();
	});
	var is_showData = [{ is_show : 1 , text: '是' }, { is_show : 0 , text: '否'}];
	//列数组
	columnsArr =  [ 
		{ display : '订单号', name : 'order_num', align : 'center' , type : 'string' , width : 130, render:function(row){
			return "<a class='link' href='javascript:void(0);' onclick='addAndEdit("+row.__index+");'>"+row.order_num+"</a>";
		} } ,
		{ display : '下单时间', name : 'add_date', align : 'center' , type : 'string', width : 160, render:function(row){
			return row.add_date.substring(0,row.add_date.length-2);
		} } ,
		{ display : '下单账号', name : 'mem_no', align : 'left', width : 160, type:'string',render:function(row){
			return "<a class='link' href='javascript:;' onclick='showMemberEdit(\""+row.mem_no+"\")'>"+row.mem_no+"</a>" ;
		} },
		{ display : '收货人', name : 'receive_name', align : 'left', width : 100, type:'string' },
		{ display : '订单金额', name : 'type', align:'right', width:100, type:'string', render:function(row){
			return (row.product_total_price+row.ship_total_price).toFixed(2);
		} },
		{ display:'订单来源', name:'pay_gateway_no', align:'center', width:100, type:'string', render:function(row){
			if($.trim(row.pay_gateway_no)!=""){
				if($.trim(row.pay_gateway_no)=="WX_M"){
					return "微信支付";
				}else if($.trim(row.pay_gateway_no)=="Alipay"){
					return "支付宝";
				}else if($.trim(row.pay_gateway_no)=="AlipayM"){
					return "支付宝手机端";
				}else{
					return "网银支付";
				}
			}
		} },
		{ display:"线下付款备注", name:"offline_pay_remark", align:"left", width:100 },
		{ display:"发货备注", name:"ship_remark", align:"left", width:100 },
		{ display:'操作记录', align:'center',width:100,render:function(row){
			return "<a href='javascript://void(0);' onclick='viewOrderOperateHistory("+row.order_num+");'>查看</a>";
		}},
		{ display:'提现类型', name:'payoff_type', align:'center', width:100, type:'string', render:function(row){
			if($.trim(row.payoff_type)!=""){
				if($.trim(row.payoff_type)=="1"){
					return "会员提现";
				}else if($.trim(row.payoff_type)=="2"){
					return "合伙人提现";
				}
			}
		} },
		{ display:'提现金额', name:'order_status', align:'center', width:100, type:'string', render:function(row){
			if(row.payoff_type=="1"){
				return row.total_junior_member_payment;
			}else if(row.payoff_type=="2"){
				if(row.p_flag=="201001"){
					return row.total_gold_partner_payment;
				}else if(row.p_flag=="201002"){
					return row.total_diamond_partner_payment;
				}else if(row.p_flag=="201003"){
					return row.total_crown_partner_payment;
				}
			}
		} }
	];
	
	/*列表页条件查询*/
	function doSearch(){
		params = [];
		conditionStr = "";
		var order_num = $.trim($("#order_num").val());
		if(order_num!=""){
			conditionStr += " and order_num='" + order_num + "'";
		}
		var receive_name = jQuery("#receive_name").val();
		if(''!=jQuery.trim(receive_name)){
			conditionStr += " and receive_name like '%"+receive_name+"%' ";
		}
		var start_date = jQuery("#add_date_start").val();
		if(''!=jQuery.trim(start_date)){
			conditionStr += " and add_date > '"+start_date+"' ";
		}
		var end_date = jQuery("#add_date_end").val() ;
		if(''!=jQuery.trim(end_date)){
		    conditionStr += " and convert(varchar,add_date,23)<='"+end_date+"'" ;
		}
		var state = jQuery("#order_status").val();
		if(''!=jQuery.trim(state)){
			conditionStr += " and order_status = "+state;
		}
		var type = $.trim($("#order_type").val());
		if(type != ""){
			conditionStr += " and order_type=" + type;
		}
		params.push({'name':'enumNo','value':'106013'});
		params.push({'name':'tableName','value':tableName});
		params.push({'name':'fields','value':fields});
		params.push({'name':'whereStr','value':whereStr+conditionStr});
		params.push({'name':'orderBy','value':orderBy});
		grid.options.parms=params;
		grid.loadData();
	}
	
	function showMemberEdit(memberNo){
		if(''!=jQuery.trim(memberNo)){
			jQuery.ajax({
				type:"post",
				url:"/backend/action/ajax_cud.jsp",
				data:{flag:"getMemberUuid",memberNo:memberNo},
				success:function(msg){
				if(''!=jQuery.trim(msg)){
					jrWindow('/backend/gift.21-sun.com/gift_member/gift_member_edit.jsp?channel_uuid=1&id='+jQuery.trim(msg),"",790,600,false) ;
				}
				}
			});
		}
	}
	
	function addAndEdit(index){
    	if(undefined==index){//如果是增加
			toolbarAdd({
				width:500,
				height:500,
				folderName:"gift.21-sun.com/gift_order",
				fileName:"gift_order",
				params:{
					channel_uuid:'<%=channelUUID%>'
				},
				title:"增加"
			});
    	}else{//如果是修改
	    	var row = grid.getRow(index);
	    	toolbarAdd({
	    		width:800,
	    		height:600,
	    		title:'查看订单',
	    		folderName:"gift.21-sun.com/gift_order",
				fileName:"gift_order"
	    	},row.uuid);
    	}
    }
    
    function viewOrderOperateHistory(order_num){
    	toolbarAdd({
			width:800,
			height:500,
			folderName:"gift.21-sun.com/gift_order",
			fileName:"gift_order_operate_history",
			params:{
				order_num:order_num
			},
			title:"订单操作记录"
		});
    }
    
    /**
	 * 列表删除方法
	 * 
	 * @param {}
	 *            arg 删除时要传的参数
	 */
	function toolbarDel(arg) {
		if (typeof(arg) == 'undefined' || arg == null) {
			arg = {};
		}
		var checkedRows = grid.getCheckedRows();
		if (checkedRows.length <= 0) {
			return;
		}
		// 遍历所有的选中行，如果是没有UUID，则移除
		jQuery.each(checkedRows, function(index, data) {
			if (typeof(this.uuid) == 'undefined') {
				jrDeleteRow(this.__index);
			}
		});
		jrConfirm("确定删除选中项吗？", function(v) {
			if (v) {
				var checkedRows = grid.getCheckedRows();
				var idStr = "";
				var noStr = "";
				for (var i = 0; i < checkedRows.length; i++) {
					idStr += "'" + checkedRows[i].uuid + "',";
					noStr += "'" + checkedRows[i].order_num + "',";
				}
				if (idStr.indexOf(",") != -1) {
					idStr = idStr.substring(0, idStr.length - 1);
					noStr = noStr.substring(0, noStr.length - 1);
				}
				arg.del_id = idStr;
				arg.del_order_no = noStr;
				if ('undefined' == typeof(arg.tableName)) {
					arg.tableName = tableName;
				}
				executeDel(arg);
			}
		});
	}
	
	function exportExcel(){
		var urlPara = "?enumNo=106013&flag=exportOrder";
		var start_date = jQuery("#add_date_start").val();
		if(''!=jQuery.trim(start_date)){
			urlPara += "&order_start_date=" + start_date;
		}
		var end_date = jQuery("#add_date_end").val();
		if(''!=jQuery.trim(end_date)){
		    urlPara += "&order_end_date=" + end_date;
		}
		var state = jQuery("#order_status").val();
		if(''!=jQuery.trim(state)){
			urlPara += "&order_status=" + state;
		}
		
		window.location.href="/backend/action/ajax_r.jsp" + urlPara;
	}
</script>